package cn.liontalk.controller;

import cn.liontalk.entity.UserEntity;
import cn.liontalk.enums.UserSexEnum;
import cn.liontalk.service.User1Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * @author: 周哲
 * @package: cn.liontalk.controller
 * @description:
 * @date: 2019/3/27 21:53
 * @version: V1.0
 */
@Api(description = "用户接口", tags = "用户接口")
@RestController
public class UserController {


    @Autowired
    private User1Service user1Service;


    @RequestMapping("/user/getAll")
    @ApiOperation(value = "查询所有用户", notes = "查询所有用户")
    public List <UserEntity> getUsers() {
        List <UserEntity> users = user1Service.getAllUsers();
        UserEntity userEntity = new UserEntity();
        userEntity.setId(100L);
        userEntity.setUserName("zhouzhe");
        userEntity.setPassWord("123456");
        users.add(userEntity);
        return users;
    }


    @RequestMapping(value = "/insert")
    @ApiOperation(value = "新增用户", notes = "新增注册")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", dataType = "Long", required = true, value = "主键", defaultValue = "100"),
            @ApiImplicitParam(paramType = "query", name = "user_id", dataType = "Long", required = true, value = "用户id", defaultValue = "10001"),
            @ApiImplicitParam(paramType = "query", name = "order_id", dataType = "Long", required = true, value = "订单id", defaultValue = "10001"),
            @ApiImplicitParam(paramType = "query", name = "nickName", dataType = "String", required = true, value = "用户昵称", defaultValue = "wangna"),
            @ApiImplicitParam(paramType = "query", name = "passWord", dataType = "String", required = true, value = "用户密码", defaultValue = "123456"),
            @ApiImplicitParam(paramType = "query", name = "userName", dataType = "String", required = true, value = "用户名称", defaultValue = "王大锤")
    })
    public String updateTransactional(@RequestParam(value = "id") Long id,
                                      @RequestParam(value = "user_id") Long user_id,
                                      @RequestParam(value = "order_id") Long order_id,
                                      @RequestParam(value = "nickName") String nickName,
                                      @RequestParam(value = "passWord") String passWord,
                                      @RequestParam(value = "userName") String userName) {
        UserEntity user2 = new UserEntity();
        user2.setId(id);
        user2.setUser_id(user_id);
        user2.setOrder_id(order_id);
        user2.setNickName(nickName);
        user2.setPassWord(passWord);
        user2.setUserName(userName);
        user2.setUserSex(UserSexEnum.WOMAN);
        user1Service.insertUser(user2);
        return "test";
    }
}
